package com.micro.frog.acct.utils;

import java.util.HashMap;
import java.util.Map;

/**
 * 自定义缓存
 *
 * @author :  ljh
 * @date : 2018/4/10
 **/
public class CacheUtil {

    protected static CacheUtil cacheUtil = null;

    private static Map<String, Object> cacheMap = new HashMap<>();

    private CacheUtil() {
    }

    public static CacheUtil newInstance() {
        if (cacheUtil == null) {
            cacheUtil = new CacheUtil();
        }
        return cacheUtil;
    }

    public static <T> T get(String key, Class<T> clazz) {
        return get(key) == null ? null : (T) get(key);
    }

    public static Object get(String key) {
        return cacheMap.get(key);
    }

    public static void put(String key, Object value) {
        cacheMap.put(key, value);
    }

    public static void delete(String key) {
        cacheMap.remove(key);
    }
}
